#!/bin/bash
echo -e "======================设置环境变量~/.bashrc========================"
# 设置开发环境变量和依赖（非docker容器场景）
# /etc/profile
if [[ ! -f "/opt/.bashrc_bak" ]]; then
    cp ~/.bashrc /opt/.bashrc_bak
    echo "备份配置文件路径：/opt/.bashrc_bak"
else
    cp -f /opt/.bashrc_bak ~/.bashrc
    echo "覆盖配置文件~/.bashrc"
fi

echo -e "
export QL_DIR=/ql
export QL_BRANCH=develop
export SHELL=/bin/bash
">>~/.bashrc
source ~/.bashrc

echo -e "\n======================赋予777权限======================"
chmod 777 ${QL_DIR}/shell/*.sh 
chmod 777 ${QL_DIR}/docker/*.sh
echo -e "${QL_DIR}/shell/*.sh\n${QL_DIR}/docker/*.sh"

echo -e "\n======================下载node_modules依赖======================"
echo -e "开始下载中..."
pnpm install --prod

echo -e "\n启动crond服务..."
# crond start |stop |restart |reload |status 启动服务
# crontab 执行tasK 脚本存在可能读取不到环境变量：task.sh脚本第一行加上source ~/.bashrc
rm -f /var/run/crond.pid
crond start

# docker/docker-entrypoint.sh脚本第一行：dir_shell=/ql/shell替换dir_shell=$QL_DIR/shell
# pm2 restart all
# pm2 logs panel